import { makeAutoObservable,action,computed,flow,runInAction } from 'mobx';
import AsyncStorage from '@react-native-async-storage/async-storage';
class Local {
  // 定义数据
  token = ""

  constructor() {
    makeAutoObservable(this,{
      setToken:action,
      getToken:flow
    })
  }
  setToken =  (str:string) => {
    this.token = str
    AsyncStorage.setItem("token",JSON.stringify(str))
  }
  get dou(){
    return 
  }
  // 你当然也可以用 async await
   *getToken(){
    this.token = yield AsyncStorage.getItem('token') || ''
  }
  //如果用async得action形式 触发我们需要调用他 runInAction
  async getTokens(){
    const token = await AsyncStorage.getItem('token') || ''
    runInAction(()=>{
      this.token = token
      // console.log(555,this.token)
    })
  }
}
// ​实力化导出
const localStore = new Local();
localStore.getTokens()
export { localStore }
